﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Caching;
using System.Data.Linq;

namespace DataObject.Core
{
    public class SqlCacheDependencyCore
    {
        public static SqlCacheDependencyCore CreateInstant()
        {
            return new SqlCacheDependencyCore();
        }
        public void StartSqlCacheDependencyTable(string ConnectionString)
        {
            using (DataContext db = new DataContext(ConnectionString))
            {
                SqlCacheDependencyAdmin.EnableNotifications(ConnectionString);
                foreach (var item in db.Mapping.GetTables())
                    if (!SqlCacheDependencyAdmin.GetTablesEnabledForNotifications(ConnectionString).Contains(item.TableName))
                        SqlCacheDependencyAdmin.EnableTableForNotifications(ConnectionString, item.TableName);
            }
        }
    }
}
